package com.ztom.daily.n2022.m5;

/**
 * 增减字符串匹配
 * <p>
 * https://leetcode.cn/problems/di-string-match/
 *
 * @author ZhangTao
 */
public class Day09DiStringMatch {

    public int[] diStringMatch(String s) {
        int n = s.length(), lo = 0, hi = n;
        int[] perm = new int[n + 1];
        for (int i = 0; i < n; ++i) {
            perm[i] = s.charAt(i) == 'I' ? lo++ : hi--;
        }
        perm[n] = lo; // 最后剩下一个数，此时 lo == hi
        return perm;
    }
}
